package com.qys.livesMall.anchor.constants.enums;

import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.common.utils.MessageUtils;

public enum AnchorSellLivesApplyStatus {
    待开播((byte) 0, "主播带货直播审核中"),
    进行中((byte) 1, "主播带货直播审核未通过"),
    待结算((byte) 2, "主播带货直播待开播"),
    已完成((byte) 3, "主播带货直播开播中"),
    未申请((byte) 4, "主播带货直播已开播完");
    private Byte status;
    private String info;

    AnchorSellLivesApplyStatus(Byte status, String info) {
        this.status = status;
        this.info = info;
    }

    public Byte getStatus() {
        return status;
    }

    public String getInfo() {
        return MessageUtils.message(info);
    }

    public static String getStatusInfoByType(Byte status) {
        AnchorSellLivesApplyStatus sellTaskStatus = getByType(status);
        return null == sellTaskStatus ? null : sellTaskStatus.getInfo();
    }

    public static AnchorSellLivesApplyStatus getByType(Byte status) {
        for (AnchorSellLivesApplyStatus anchorSellTaskStatus : values()) {
            if (anchorSellTaskStatus.getStatus().equals(status)) {
                return anchorSellTaskStatus;
            }
        }
        return null;
    }


    /**
     * nowStatus:当前状态
     * args:需要满足的状态
     */
    public static void checkStatus(Byte nowStatus, AnchorSellLivesApplyStatus... args) {
        if (null == nowStatus) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        for (AnchorSellLivesApplyStatus s : args) {
            if (nowStatus.equals(s.getStatus())) {
                return;
            }
        }
        throw new QysException(getStatusInfoByType(nowStatus));
    }


    /**
     * 判断状态是否存在
     */
    public static AnchorSellLivesApplyStatus statusExists(Byte status) {
        if (null == status) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        AnchorSellLivesApplyStatus sellTaskStatus = getByType(status);
        if (null==sellTaskStatus){
            throw new QysException(MessageUtils.message("主播带货任务状态错误",status));
        }
        return sellTaskStatus;
    }
}
